From 7a966c632d20a4b79246d2ae8511389046b2c42a Mon Sep 17 00:00:00 2001 From: "iap10@labyrinth.cl.cam.ac.uk" Date: Tue, 8 Feb 2005 00:28:11 +0000 Subject: [PATCH] bitkeeper revision 1.1159.212.116 (4208079bssB3TTrruGComoEvhNrq9Q) Fix some of the time virtualization issues. - Compute the elapsed time correctly in the cpu loop - Try to inject interrupts in the vmexit handler Signed-off-by: Edwin Zhai Signed-off-by: Arun Sharma Signed-off-by: ian@xensource.com --- tools/ioemu/iodev/cpu.cc | 32 ++++++++++++++++++++++++-------- xen/arch/x86/vmx.c | 2 ++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/tools/ioemu/iodev/cpu.cc b/tools/ioemu/iodev/cpu.cc index 17a85539ce..11e761d774 100644 --- a/tools/ioemu/iodev/cpu.cc +++ b/tools/ioemu/iodev/cpu.cc @@ -167,6 +167,9 @@ bx_cpu_c::timer_handler(void) #define rdtscl(low) \ __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx") +#define rdtscll(val) \ + __asm__ __volatile__("rdtsc" : "=A" (val)) + void bx_cpu_c::cpu_loop(int max_instr_count) { @@ -180,7 +183,8 @@ bx_cpu_c::cpu_loop(int max_instr_count) FD_ZERO(&rfds); while (1) { - unsigned long t1, t2; + static unsigned long long t1 = 0; + unsigned long long t2; /* Wait up to one seconds. */ tv.tv_sec = 0; @@ -188,18 +192,30 @@ bx_cpu_c::cpu_loop(int max_instr_count) FD_SET(evtchn_fd, &rfds); send_event = 0; - rdtscl(t1); + + if (t1 == 0) // the first time + rdtscll(t1); + retval = select(evtchn_fd+1, &rfds, NULL, NULL, &tv); - rdtscl(t2); if (retval == -1) { perror("select"); return; } - //stime_usec = 1000000 * (1 - tv.tv_sec) - tv.tv_usec; - if (t2 > t1) - BX_TICKN((t2 - t1) / 2000); // should match ips in bochsrc + + rdtscll(t2); + +#if __WORDSIZE == 32 +#define ULONGLONG_MAX 0xffffffffffffffffULL +#else +#define ULONGLONG_MAX ULONG_MAX +#endif + + if (t2 <= t1) + BX_TICKN((t2 + ULONGLONG_MAX - t1)); else - BX_TICKN((MAXINT - t1 + t2) / 2000); // should match ips in bochsrc + BX_TICKN((t2 - t1)); + t1 = t2; + timer_handler(); if (BX_CPU_INTR) { #if BX_SUPPORT_APIC @@ -248,7 +264,7 @@ bx_cpu_c::interrupt(Bit8u vector) // page. rdtscl(tscl); - BX_INFO(("%lx: injecting vector: %x\n", tscl, vector)); + BX_DEBUG(("%lx: injecting vector: %x\n", tscl, vector)); intr = &(((vcpu_iodata_t *) shared_page)->vp_intr[0]); set_bit(vector, intr); diff --git a/xen/arch/x86/vmx.c b/xen/arch/x86/vmx.c index 67c08d073f..486998c34a 100644 --- a/xen/arch/x86/vmx.c +++ b/xen/arch/x86/vmx.c @@ -927,6 +927,8 @@ asmlinkage void vmx_vmexit_handler(struct xen_regs regs) default: __vmx_bug(®s); /* should not happen */ } + + vmx_intr_assist(d); return; } -- 2.30.2